import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import {getCookie, setCookie} from "../utils/utils";

Vue.use(VueRouter)

const routes = [
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/login/index.vue')
    },
    {
        path: '/', redirect: "/tableList"
    },
    {

        path: '/bind2',
        name: 'bind2',
        component: () => import('../views/bind/bind2.vue')
    },
    {

        path: '/g6',
        name: 'g6',
        component: () => import('../views/g6/g6.vue')
    },
    {

        path: '/tableNet',
        name: 'tableNet',
        component: () => import('../views/tableNet/tableNet.vue')
    },

    {

        path: '/tableList',
        name: 'tableList',
        component: () => import('../views/tableList/tabeList.vue')
    },
    {

        path: '/createCvs',
        name: 'createCvs',
        desc: 'service controller view的代码生成',
        component: () => import('../views/createCvs/createCvs.vue')
    },

    {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
    },
    {
        path: '/showTable',
        name: 'showTable',
        component: () => import("../views/showTable/showTable")
    },
    {
        /*文章编辑器*/
        path: '/storyEdit',
        name: 'storyEdit',
        component: () => import("../views/story/storyEdit.vue")
    },
    {
        /*查询文章界面*/
        path: '/storyEditDailog',
        name: 'storyEditDailog',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/story/storyEditDailog.vue")
    },
    {
        /*查询文章列表*/
        path: '/storyList',
        name: 'storyList',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/story/list.vue")
    },
    {
        /*单纯显示文字*/
        path: '/storyOne',
        name: 'storyOne',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/story/one.vue")
    },
    {
        /*单纯显示文字*/
        path: '/storyTranslate',
        name: 'storyTranslate',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/story/translate.vue")
    },
    {
        /*单纯显示文字*/
        path: '/value2json',
        name: 'value2json',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/utils/value2json.vue")
    },
    {
        /*单纯显示文字*/
        path: '/urlparse',
        name: 'urlparse',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/utils/urlparse.vue")
    },
    {
        /*自定义字段demo*/
        path: '/fieldsList',
        name: 'fields/list',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fields/list.vue")
    },
    {
        /*自定义字段demo*/
        path: '/fieldsModify',
        name: 'fields/modify',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fields/modify.vue")
    },
    {
        /*自定义字段demo*/
        path: '/fieldTypeList',
        name: 'fieldType/list',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fieldType/list.vue")
    },
    {
        /*自定义字段demo*/
        path: '/fieldTypeModify',
        name: 'fieldType/modify',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fieldType/modify.vue")
    },
    {
        /*自定义字段demo*/
        path: '/fieldTypeList',
        name: 'fieldType/list',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fieldType/list.vue")
    },
    {
        /*自定义字段demo*/
        path: '/supplierList',
        name: 'supplierList',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fields/supplier/list.vue")
    },
    {
        /*自定义字段demo*/
        path: '/supplierDetail',
        name: 'supplierDetail',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/fields/supplier/detail.vue")
    },
    {
        /*自定义字段demo*/
        path: '/imageList',
        name: 'imageList',
        // http://192.168.10.134:8080/storyEditDailog?uuid=6b5f2f7b-a228-414f-ab8d-2bb7578b2b44&puuid=1&title=1
        component: () => import("../views/imageList/imageList.vue")
    },




]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

function isLogin() {
    if (getCookie('currentUser')) {
        return true;
    } else {
        return false
    }
}

if (!isLogin()) {
    setCookie("currentUser", "")
}


//去掉没有登录 跳转首页
/*router.beforeEach((to, from, next) => {
    //拦截没有登录的时候的路由请求
    if (to.path != '/login') {
        if (!isLogin()) {
            //还没有登录
            location.href = "/login"
            return false;
        }
    }

    next();

})*/

export default router
